/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.octgame.resources;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.newdawn.slick.Font;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.loading.LoadingList;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 *
 * @author Hempa
 */
public class Resources {
    private static Resources _instance = new Resources();

    private Map<String, Font> fontMap;

    private Resources() {}
    private Document doc;

    public final static Resources getInstance() {
        return _instance;
    }

    public void loadResources( InputStream is ) throws SlickException
    {
        DocumentBuilderFactory dbf = null;
        DocumentBuilder db = null;
        try {
            dbf = DocumentBuilderFactory.newInstance();
            db = dbf.newDocumentBuilder();
            
        } catch (Exception e) {
            throw new SlickException("Unable to load resources", e);
        }

        try {
            doc = db.parse(is);
        } catch (SAXException e) {
            throw new SlickException("Could not load resources", e);
        } catch (IOException e) {
            throw new SlickException("Could not load resources", e);
        }


        doc.getDocumentElement().normalize();
        NodeList nodes = doc.getElementsByTagName("resource");
        int totalResources = nodes.getLength();

        LoadingList.setDeferredLoading(true);

    }
}
